package tclp.simpleocr;

import java.awt.Frame;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import net.sourceforge.javaocr.gui.meanSquareOCR.TrainingImageSpec;
import net.sourceforge.javaocr.ocrPlugins.mseOCR.TrainingImage;
import net.sourceforge.javaocr.ocrPlugins.mseOCR.TrainingImageLoader;

/**
 * 
 * @author Absatz Leoš
 */
public class TrainingImageUtils {

  public static HashMap<Character, ArrayList<TrainingImage>> getTrainingImageHashMap(TrainingImageSpec... imgs) throws
      Exception {
    ArrayList<TrainingImageSpec> list = new ArrayList(Arrays.asList(imgs));
    return getTrainingImageHashMap(list);
  }

  public static HashMap<Character, ArrayList<TrainingImage>> getTrainingImageHashMap(ArrayList<TrainingImageSpec> imgs) throws
      Exception {
    TrainingImageLoader loader = new TrainingImageLoader();
    HashMap<Character, ArrayList<TrainingImage>> trainingImages = new HashMap<Character, ArrayList<TrainingImage>>();
    Frame frame = new Frame();

    for (int i = 0; i < imgs.size(); i++) {
      loader.load(
          frame,
          imgs.get(i).getFileLocation(),
          imgs.get(i).getCharRange(),
          trainingImages);
    }

    return trainingImages;
  }
}
